<?php
namespace Home\Model;
use Think\Model;
class JurisdictionModel extends Model{
    //修改权限
    public function uppjurisdiction($data){
        $hasUser=$this->hasuser($data['user_id']);
        if($hasUser['status']==1){
            $where['user_id']=$data['user_id'];
            $jurInfo=$this->where($where)->save($data);
        }
        if($jasUser['status']==2){
            $jurInfo=$this->add($data);
        }
        if($jasUser['status']==3){
            $jurInfo=false;
        }
        return $jurInfo;
    }
    protected function hasuser($user_id){
        if($user_id){
            $data['status']=3;
        }
        $where['user_id']=$user_id;
        $jurInfo=$this->where($where)->find();
        if($jurInfo){
            $data['status']=1;
        }else{
            $data['status']=2;
        }
        return $data;
    }
    
    public function hasjur($user_id){
    	$where['user_id']=$user_id;
    	$join="__JURISDICTION_TYPE__ t on j.user_jur=t.id ";
    	return $this->alias('j')
    				->where($where)
    				->join($join)
    				->find();
    }
}